package Offer.offer;

import java.util.Arrays;

/**
 * Created by 雷文康 on 2018/1/6.
 */
public class Test43N个骰子的点数 {
    public static void main(String[] args) {
        printProbability(4);
    }
    public static void printProbability(int n){
        if (n < 1){
            return;
        }
        int[] array1 = new int[6 * n + 1];
        int[] array2 = new int[6 * n + 1];
        Arrays.fill(array1, 0);
        Arrays.fill(array2, 0);
        Arrays.fill(array1, 1, 7, 1);
        for (int i = 2; i <= n ; i++) {
            for (int j = i; j <= 6 * i; j++) {//每次循环确定和为i到6i的可能个数 如i = 2时，求出2到12的可能次数
                int sum = 0;
                if (j < 7) {
                    for (int k = 1; k < j; k ++){
                        sum += array1[k];
                    }
                } else {
                    for (int k = j - 6; k < j; k++) {
                        sum+= array1[k];
                    }
                }
                array2[j] = sum;
            }

            /*
            交换array1和array2
             */

            //先将array2赋值给array1
            for (int j = 0; j < array2.length; j++) {
                array1[j] = array2[j];
            }
            //array2初始化
            Arrays.fill(array2, 0);
        }
        //最终结果保存在array1的n到6n位上
        for (int i = n; i <= 6 * n; i++) {
            System.out.println("出现次数 : " + i + "的可能次数有" + array1[i] + "种");
        }

    }
}
